#!/usr/bin/python
# -*- coding: UTF-8 -*-
import json
import requests

ip_position_url = "http://ip-api.com/json/"

def get_proxy():
	return requests.get("http://127.0.0.1:5010/get/").json()

class IPPosintionOnline(object):
	"""docstring for IPPosintionOnline"""
	# def __init_null_data(self, para):
	# 	self.country = 'null'
	# 	self.region = 'null'

	def __init__(self):
		super(IPPosintionOnline, self).__init__()
		self.update_ip_position_online(self)

		# self.country = 
		
	def update_ip_position_online(self, para):
		# proxy = get_proxy().get('proxy')

		json_page = requests.get(ip_position_url)
		json_page_json = json.loads(json_page.text)
		# print(json_page_json["country"])
		self.country = json_page_json['country']
		self.region = json_page_json['regionName']
		self.city = json_page_json['city']
		self.latitude = json_page_json['lat']
		self.longitude = json_page_json['lon']
		self.ip = json_page_json['query']

if __name__ == '__main__':
	positions = IPPosintionOnline()
	print(positions.region.lower())
	print(positions.ip)

